package com.ddn.service.personnel.impl;

import com.ddn.mapper.personnel.ExamMapper;
import com.ddn.model.personnel.Exam;
import com.ddn.model.personnel.ExamVO;
import com.ddn.service.personnel.ExamService;
import com.ddn.util.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;

/**
 * @author Bikakaso
 * @date 2023/1/1
 * ddn_hotel
 */
@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    private ExamMapper examMapper;

    @Override
    public ResultData findAll(HashMap<String, Object> map) {
        String page = (String) map.get("page");
        String limit = (String) map.get("limit");
        System.out.println("map = " + map);
        String ttt = (String) map.get("name");
        map.put("ttt",ttt);
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        List<ExamVO> list = examMapper.findAll(map);
        PageInfo<ExamVO> info = new PageInfo<>(list);
        if (list != null) {
            return ResultData.ok(list, info.getTotal());
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteById(int id) {
        int i = examMapper.deleteById(id);
        if (i > 0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteBatch(int[] ids) {
        int i = examMapper.deleteBatch(ids);
        if (i > 0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData add(HashMap<String, Object> map) {
        String name = (String) map.get("emplId");
        Integer ids = examMapper.selectId(name);
        System.out.println("ids ====== " + ids);
        if (ids != null) {
            map.put("ids",ids);
            int i = examMapper.add(map);
            if (i > 0) {
                return ResultData.ok();
            }
        }
        return ResultData.fail();
    }

    @Override
    public ResultData edit(HashMap<String,Object> map) {
        int i = examMapper.edit(map);
        if (i > 0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }
}
